#ifndef AIRPLANE_H
#define AIRPLANE_H

#include "Game Engine\Header\Vehicle.h"

class Airplane : public Vehicle
{
public:

	Airplane();
	//  The PropPlane constructor calls the
	//  SimpleProjectile constructor and initializes
	//  the value of the PropPlane class fields.
	Airplane( double x, double y, double z, 
		double vx, double vy, double vz, double time,
		double wingArea, double wingSpan, double tailArea,
		double clSlope0, double cl0, double clSlope1,
		double cl1, double alphaClMax,
		double cdp, double eff, double mass, 
		double enginePower, double engineRps,
		double propDiameter, double a, double b );

	void Init( ID3D10Device* device, btDynamicsWorld* world, std::wstring chassis,
		std::wstring wheels, std::wstring ground, ID3D10Effect* fx, ID3D10ShaderResourceView* cubeMap, float mass,
		bool useShadows = true );

	//  This method updates the velocity and location
	//  of the plane using a 4th order Runge-Kutta
	//  solver to integrate the equations of motion.
	void UpdateLocationAndVelocity( double dt );

	//  The getRightHandSide() method returns the right-hand
	//  sides of the equations of motion for the prop plane.
	//  q[0] = vx = dxdt
	//  q[1] = x
	//  q[2] = vy = dydt
	//  q[3] = y
	//  q[4] = vz = dzdt
	//  q[5] = z
	//************************************************************
	//  This method solves for the plane motion using a
	//  4th-order Runge-Kutta solver
	//************************************************************
	void RungeKutta4( double ds );

	void RightHandSide( double *q, double *deltaQ, double ds, 
                             double qScale, double *dq );

	void Move( float dt );

	void SetGroundPosition( D3DXVECTOR3 pos );
	void SetGroundRotation( D3DXVECTOR3 angle );

	double GetBank();
	D3DXVECTOR3	GetLook();

	float	GetWidth( UINT meshIndex = 0 );
	float	GetHeight( UINT meshIndex = 0 );
	float	GetLength( UINT meshIndex = 0 );

	void Draw( D3DXMATRIX& lightViewProj );
	void DrawToShadowMap( ID3D10EffectMatrixVariable* mfxBuildShadowMapLightWVPVar,
		ID3D10EffectShaderResourceVariable* mfxBuildShadowMapDiffuseMapVar,
		ID3D10EffectPass* pass,	D3DXMATRIX& lightViewProj );

	double	mThrottle;

	float	mClimbAngle;
	float	mHeadingAngle;
	float	mClimbRate;
	float	mAltitude;
	float	mAirSpeed;
protected:
	void Reset();
	void GetGround();

private:
	Mesh*	mGroundMesh;
	D3DXVECTOR3	mGroundPosition;
	D3DXVECTOR3 mGroundRotation;
	float	mGroundDistance;

	int		mNumEqns;
	double	mS;
	double	mQ[6];

	double	mBank;
	double	mAlpha;  //  angle of attack
	double	mWingArea;
	double	mWingSpan;
	double	mTailArea;
	double	mClSlope0;    // slope of Cl-alpha curve
	double	mCl0;         // intercept of Cl-alpha curve
	double	mClSlope1;    // post-stall slope of Cl-alpha curve
	double	mCl1;         // post-stall intercept of Cl-alpha curve
	double	mAlphaClMax;  // alpha when Cl=Clmax
	double	mCdp;         // parasite drag coefficient
	double	mEff;         // induced drag efficiency coefficient
	double	mMass;
	double	mEnginePower;
	double	mEngineRps;   // revolutions per second
	double	mPropDiameter;
	double	mA;           //  propeller efficiency coefficient
	double	mB;           //  propeller efficiency coefficient
	char*	mFlap;        //  flap deflection amount

};

#endif